from datetime import timedelta
# 15.
from redis import StrictRedis
import logging


class MyConfig(object):
    DEBUG = True
    SQLALCHEMY_DATABASE_URI = 'mysql://root:mysql@127.0.0.1:3306/information18'
    SQLALCHEMY_TRACK_MODIFICATIONS = False

    # 当回话结束的时候 commit 自动提交
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True

    REDIS_HOST = '127.0.0.1'
    REDIS_PORT = 6379

    SESSION_TYPE = 'redis'
    SESSION_USE_SIGNER = True
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT)
    PERMANENT_SESSION_LIFETIME = timedelta(days=2)
    SECRET_KEY = 'CESHI'

    # 设置日志级别
    LEVEL_NAME = logging.DEBUG


# 开发阶段配置
class DevelopConfig(MyConfig):
    pass


# 生产(线上)阶段配置
class ProductConfig(MyConfig):
    DEBUG = False
    LEVEL_NAME = logging.ERROR


# 测试阶段配置
class TestConfig(MyConfig):
    # 测试模式 TESTING = True
    TESTING = True


# 提供配置信息入口,根据需求来选择不同阶段的配置信息函数
config_dict = {
    "develop": DevelopConfig,
    "product": ProductConfig,
    "test": TestConfig,
}
